package cn.sofwin.web.blog.servlet;

import cn.sofwin.core.utils.HttpUtils;
import cn.sofwin.web.blog.utils.FileHelper;
import org.apache.commons.io.FileUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

@WebServlet("/blog/test")
public class TestServlet extends HttpServlet {
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String root= FileHelper.getWebRootPath(TestServlet.class);

        String filePath=root+"/static/upload/hello";
        System.out.println(filePath);
        File file =new File(filePath);
        String text = FileUtils.readFileToString(file,"utf-8");

        HttpUtils.writeText(resp,text);
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
}
